class Solution {
public:
    bool Anagram(string& s1, string& s2) {
        if (s1.size() != s2.size()) return false;
        int c1[26] = { 0 }, c2[26] = { 0 };
        for (int i = 0; i < s1.size(); i++)
            c1[s1[i] - 'a']++, c2[s2[i] - 'a']++;

        for (int i = 0; i < 26; i++)
            if (c1[i] != c2[i]) return false;

        return true;
    }
    vector<string> removeAnagrams(vector<string>& words) {
        vector<string> ret;
        ret.push_back(words[0]);
        for (auto& word : words) {
            string s = ret.back();
            if (!Anagram(s, word)) ret.push_back(word);
        }
        return ret;
    }
};